package com.ternnetwork.batch.quartz.job;

import java.util.Date;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerContext;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.ternnetwork.commons.utils.DateUtils;



/**
 * 
 * Quartz作业类
 * @author xuwenfeng
 *
 */
public class TestUserLauncherJob extends QuartzJobBean {

	
	
	
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		
	
		try {
			
			SchedulerContext schedulerContext = context.getScheduler().getContext();
			
			
			JobLauncher jobLauncher = (JobLauncher) schedulerContext.get("jobLauncher");
			
			JobLocator jobLocator = (JobLocator) schedulerContext.get("jobLocator");
			
			Job job = jobLocator.getJob("testUserJob");
				
			JobParametersBuilder p=(new JobParametersBuilder());
	    	p.addString("date",DateUtils.format(new Date(), DateUtils.FORMAT_DATE_TIME_YYYYMMDDHHMMSS));
	    
			
			
			jobLauncher.run(job, p.toJobParameters());
			
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
	
	
		
	}

}